<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-col :span="24">
          <el-row gutter="15">
            <el-col :span="10">
              <el-form-item label="课程编号" prop="code">
                <el-input v-model="formData.code" placeholder="请输入课程编号" clearable :style="{width: '100%'}">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="课程学科" prop="subject">
                <el-input v-model="formData.subject" placeholder="请输入课程学科" clearable :style="{width: '100%'}">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="24">
          <el-row gutter="15">
            <el-col :span="10">
              <el-form-item label="课程名称" prop="name">
                <el-input v-model="formData.name" placeholder="请输入课程名称" clearable :style="{width: '100%'}">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="课程价格" prop="price">
                <el-input v-model="formData.price" placeholder="请输入课程价格" clearable :style="{width: '100%'}">
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="24">
          <el-row gutter="15">
            <el-col :span="10">
              <el-form-item label="适用人群" prop="applicable_person">
                <el-input v-model="formData.applicable_person" placeholder="请输入适用人群" clearable
                  :style="{width: '100%'}"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="课程有效期" prop="field109">
                <el-time-picker v-model="formData.field109" is-range format="HH:mm:ss" value-format="HH:mm:ss"
                  :style="{width: '100%'}" start-placeholder="开始时间" end-placeholder="结束时间" range-separator="至"
                  clearable></el-time-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="24">
          <el-row gutter="15">
            <el-col :span="10">
              <el-form-item label="课程封面" prop="field111" required>
                <el-upload ref="field111" :file-list="field111fileList" :action="field111Action"
                  :before-upload="field111BeforeUpload">
                  <el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="推荐指数" prop="field112">
                <el-rate v-model="formData.field112"></el-rate>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="18">
          <el-form-item label="课程介绍" prop="info">
            <el-input v-model="formData.info" type="textarea" placeholder="请输入课程介绍"
              :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        code: undefined,
        subject: undefined,
        name: undefined,
        price: 0,
        applicable_person: undefined,
        field109: null,
        field111: null,
        field112: 0,
        info: undefined,
      },
      rules: {
        code: [{
          required: true,
          message: '请输入课程编号',
          trigger: 'blur'
        }],
        subject: [{
          required: true,
          message: '请输入课程学科',
          trigger: 'blur'
        }],
        name: [{
          required: true,
          message: '请输入课程名称',
          trigger: 'blur'
        }],
        price: [{
          required: true,
          message: '请输入课程价格',
          trigger: 'blur'
        }],
        applicable_person: [{
          required: true,
          message: '请输入适用人群',
          trigger: 'blur'
        }],
        field109: [{
          required: true,
          message: '课程有效期不能为空',
          trigger: 'change'
        }],
        field112: [{
          required: true,
          message: '推荐指数不能为空',
          trigger: 'change'
        }],
        info: [],
      },
      field111Action: 'https://jsonplaceholder.typicode.com/posts/',
      field111fileList: [],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    field111BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    },
  }
}

</script>
<style>
.el-upload__tip {
  line-height: 1.2;
}

.el-rate {
  display: inline-block;
  vertical-align: text-top;
}

</style>
